//
//  RssListViewController.m
//  iBole
//
//  Created by Tao Chen on 12-3-11.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
/*This file is part of iBole.
 
 iBole is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 iBole is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */
#import "RssListViewController.h"
#import "RssDetailViewController.h"

@implementation RssListViewController
{
    RssList * rssList;
    RssDetailViewController * childController;
}
@synthesize rssList;

-(void)viewDidLoad
{
    [super viewDidLoad];
    [self.rssList getRssFromNetwork];
}
-(void)viewDidUnload
{
    self.rssList = nil;
    [super viewDidUnload];
}
-(void)dealloc
{
    [rssList release];
    [super dealloc];
}
#pragma mark -
#pragma mark table data source methods
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   return [rssList itemNumforPage:0];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * RssListCellID = @"RssListCellID";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:RssListCellID];
    if (!cell) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:RssListCellID] autorelease];
    }
    NSUInteger row = [indexPath row];
    RssDetail * detail = [self.rssList detailAtIndex:row];
    cell.textLabel.text = detail.title;
    cell.detailTextLabel.text = detail.summary;
    return cell;
}
#pragma mark -
#pragma mark table delegate methods
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (!childController) {
        childController = [[RssDetailViewController alloc] initWithNibName:@"RssDetail" bundle:nil];
    }
    NSUInteger row = [indexPath row];
    RssDetail * detail = [self.rssList detailAtIndex:row];
    childController.title = detail.title;
    childController.info = detail.detail;
    [self.navigationController pushViewController:childController animated:YES];
}



@end
